/**
     *
     */

package com.xyz.frame.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Lists;
import com.xyz.frame.bean.app.dto.IndexImgDto;
import com.xyz.frame.bean.app.dto.TabBarDto;
import com.xyz.frame.bean.model.IndexImg;
import com.xyz.frame.common.response.ServerResponseEntity;
import com.xyz.frame.service.IndexImgService;
import com.xyz.frame.sys.service.SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.List;

/**
 * 
 */
@RestController
@Tag(name = "首页轮播图接口")
@Slf4j
public class AdminIndexImgController {

    @Autowired
    private IndexImgService indexImgService;

    @Value("${prodFlag}")
    private Boolean prodFlag;

    /**
     * 首页轮播图接口
     */
    @GetMapping("/indexImgs")
    @Operation(summary = "首页轮播图", description = "获取首页轮播图列表信息")
    public ServerResponseEntity<List<IndexImgDto>> indexImgs() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        log.info("===>indexImgs=>request.header:{}",request.getHeader("appTypeId"));
        List<IndexImg> indexImgList = indexImgService.listIndexImg(request.getHeader("appTypeId"));
        List<IndexImgDto> indexImgDtos = BeanUtil.copyToList(indexImgList, IndexImgDto.class);
        return ServerResponseEntity.success(indexImgDtos);
    }


    @Autowired
    private SysConfigService sysConfigService;
    /**
     * prodFlag
     */
    @GetMapping("/prodFlag")
    @Operation(summary = "prodFlag", description = "prodFlag")
    public ServerResponseEntity<Boolean> prodFlag() {
        //false：不展示不合规组件
        String value = sysConfigService.getValue("ai-edu-prodFlag");
        return ServerResponseEntity.success(Boolean.valueOf(value));
//        return ServerResponseEntity.success(true);
    }
    /**
     * tabbar
     */
    @GetMapping("/tabbar")
    @Operation(summary = "tabbar", description = "tabbar")
    public ServerResponseEntity<List<TabBarDto>> tabbar() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        log.info("===>tabbar=>request.header:{}",request.getHeader("appTypeId"));
        List<TabBarDto> tabBarDtoList = Lists.newArrayList();
        TabBarDto tabBarDto = new TabBarDto();
        tabBarDto.setName("首页");
        tabBarDto.setType(0);
        tabBarDto.setCurrent(0);
        tabBarDto.setIcon("/static/images/tabbar/homepage.png");
        tabBarDto.setSelectIcon("/static/images/tabbar/homepage-sel.png");
        tabBarDto.setUrl("/pages/index/index");
        tabBarDtoList.add(tabBarDto);

//        tabBarDto = new TabBarDto();
//        tabBarDto.setName("分类");
//        tabBarDto.setType(0);
//        tabBarDto.setCurrent(1);
//        tabBarDto.setIcon("/static/images/tabbar/category.png");
//        tabBarDto.setSelectIcon("/static/images/tabbar/category-sel.png");
//        tabBarDto.setUrl("/pages/category/category");
//        tabBarDtoList.add(tabBarDto);
//
//        tabBarDto = new TabBarDto();
//        tabBarDto.setName("购物车");
//        tabBarDto.setType(0);
//        tabBarDto.setCurrent(2);
//        tabBarDto.setIcon("/static/images/tabbar/basket.png");
//        tabBarDto.setSelectIcon("/static/images/tabbar/basket-sel.png");
//        tabBarDto.setUrl("/pages/basket/basket");
//        tabBarDtoList.add(tabBarDto);
//
//        tabBarDto = new TabBarDto();
//        tabBarDto.setName("我的");
//        tabBarDto.setType(0);
//        tabBarDto.setCurrent(3);
//        tabBarDto.setIcon("/static/images/tabbar/user.png");
//        tabBarDto.setSelectIcon("/static/images/tabbar/user-sel.png");
//        tabBarDto.setUrl("/pages/user/user");
//        tabBarDtoList.add(tabBarDto);



        tabBarDto = new TabBarDto();
        tabBarDto.setName("智学");
        tabBarDto.setType(0);
        tabBarDto.setCurrent(1);
        tabBarDto.setIcon("/static/images/tabbar/zx.png");
        tabBarDto.setSelectIcon("/static/images/tabbar/zx-sel.png");
        tabBarDto.setUrl("/pages/ai/ai");
        tabBarDtoList.add(tabBarDto);

        tabBarDto = new TabBarDto();
        tabBarDto.setName("我的");
        tabBarDto.setType(0);
        tabBarDto.setCurrent(2);
        tabBarDto.setIcon("/static/images/tabbar/user.png");
        tabBarDto.setSelectIcon("/static/images/tabbar/user-sel.png");
        tabBarDto.setUrl("/pages/user/user");
        tabBarDtoList.add(tabBarDto);


//        tabBarDto = new TabBarDto();
//        tabBarDto.setName("推荐");
//        tabBarDto.setType(0);
//        tabBarDto.setCurrent(4);
//        tabBarDto.setIcon("/static/images/tabbar/user.png");
//        tabBarDto.setSelectIcon("/static/images/tabbar/user-sel.png");
//        tabBarDto.setUrl("/pages/friends/friends");
//        tabBarDtoList.add(tabBarDto);
//
//
//        tabBarDto = new TabBarDto();
//        tabBarDto.setName("个人中心");
//        tabBarDto.setType(0);
//        tabBarDto.setCurrent(5);
//        tabBarDto.setIcon("/static/images/tabbar/my.png");
//        tabBarDto.setSelectIcon("/static/images/tabbar/my-on.png");
//        tabBarDto.setUrl("/pages/xqUser/index");
//        tabBarDtoList.add(tabBarDto);

        return ServerResponseEntity.success(tabBarDtoList);
    }
}
